﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NPOI.HSSF.UserModel;
using System.IO;
using NPOI.SS.UserModel;

namespace HRWEB.HtmlHelpers
{
    public static class ExcelHelper
    {
        public static byte[] DownLoadHelper(HSSFWorkbook xls, string xlsName) { 
            using (MemoryStream ms = new MemoryStream()) { 
            xls.Write(ms); ms.Flush(); ms.Position = 0; 
            HttpResponse response = System.Web.HttpContext.Current.Response; 
            response.Clear(); 
            response.Charset = "UTF-8"; 
            response.ContentType = "application/vnd.ms-excel";                                                    System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=" + HttpUtility.UrlEncode(xlsName)));
            byte[] data = ms.ToArray(); return data;
            }
        }
        public static void SetCellBorder(this IRow row)
        {
            foreach (ICell cell in row.Cells)
            {
                cell.CellStyle.BorderTop = BorderStyle.THIN;
                cell.CellStyle.BorderRight = BorderStyle.THIN;
                cell.CellStyle.BorderBottom = BorderStyle.THIN;
                cell.CellStyle.BorderLeft = BorderStyle.THIN;
            }
        }
    }
}